
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var matchId = 0;
    var roundId = 0;
    var Controller = {
        index: function () {

            matchId = $('#matchId').val();
            roundId = $('#roundId').val();
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'match/roundmember/index' + location.search + '&mid='+matchId+'&round_id='+roundId,
                    add_url: 'match/roundmember/add?matchId='+matchId+'&round_id='+roundId,
                    edit_url: 'match/roundmember/edit',
                    del_url: 'match/roundmember/del',
                    multi_url: 'match/roundmember/multi',
                    //import_url: 'match/roundmember/import',
                    table: 'match_round_member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),visible:false},
                        {field: 'match_id', title: __('Match_id'),visible:false},
                        {field: 'match.name', title: __('Match.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'round_id', title: __('Round_id'),visible:false},
                        {field: 'round.title', title: __('Round.title'), operate: 'LIKE'},
                        {field: 'group_number', title: __('Group_number')},
                        {field: 'group_inner_number', title: __('Group_inner_number')},
                        {field: 'member_id', title: __('Member_id'),visible:false},
                        {field: 'member.real_name', title: __('Member.real_name'), operate: 'LIKE'},
                        {field: 'member.mobile', title: __('Member.mobile'), operate: 'LIKE'},
                        {field: 'score', title: __('Score'), operate:'BETWEEN'},
                        {field: 'is_out', title: '出局', searchList:{'0': '否','1':'是'},formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                rowStyle:function (value,row,index){
                    console.log(value);
                    console.log(row);
                    return {
                        css:{'background':value.color[0]}
                    };
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-round_id").data("params", function (obj) {
                return {"custom[match_id]":$("#c-match_id").val()};
            });

            $("#c-member_id").data("params", function (obj) {
                return {"custom[match_id]":$("#c-match_id").val()};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
